package com.mzj.saas.mservice.contract.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.contract.service.ContractService;
import com.mzj.saas.mservice.contract.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 合同管理
 */
@Controller
@RequestMapping("/contract")
public class ContractController {
    private static final Logger LOG = LoggerFactory.getLogger(ContractController.class);
    @Autowired
    private ContractService contractService;

    /*
     *合同设置列表信息展示
     */

    /**
     * 实现了合同设置列表信息展示
     * @param accessToken 权限鉴定
     * @param pageNumber 当前页
     * @param pageSize 页数
     * @param filter 合同设置列表条件筛查实体类
     * @return
     */
    @PostMapping("contractSetShowListInfo")
    @ResponseBody
    public ResultBean<Object> contractSetShowListInfo(@RequestHeader String accessToken, @RequestParam(defaultValue = "0") Integer pageNumber,
                                                      @RequestParam(defaultValue = "10") Integer pageSize, ContractSetSearchRequestVO filter) {
        return contractService.contractSetShowListInfo(accessToken, pageNumber, pageSize, filter);
    }

    /*
     *修改合同状态
     * status：0禁用 1启用  默认启用
     */

    /**
     * 修改合同状态
     * @param accessToken 权限鉴定
     * @param status 0禁用 1启用  默认启用
     * @param contractTemplateNumber 模板合同序号
     * @return
     */
    @PostMapping("changeContractSetStatus")
    @ResponseBody
    public ResultBean<Object> changeContractSetStatus(@RequestHeader String accessToken, @RequestParam(name = "status", required = false) Integer status, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber) {
        return contractService.changeContractSetStatus(accessToken, status, contractTemplateNumber);
    }
    /**
     * 合同模板删除,删除模板
     * @param accessToken 权限鉴定
     * @param contractTemplateNumber 模板合同序号
     * @return
     */
    @PostMapping("deleteContractTemplate")
    @ResponseBody
    public ResultBean<Object> deleteContractTemplate(@RequestHeader String accessToken, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber) {
        return contractService.deleteContractTemplate(accessToken, contractTemplateNumber);
    }

    /*
     *合同字段显示
     */

    /**
     * 合同字段显示,实现了合同字段的详细显示
     * @param accessToken 权限鉴定
     * @param contractTemplateNumber 合同编号
     * @return
     */
    @PostMapping("contractFieldShow")
    @ResponseBody
    public ResultBean<Object> contractFieldShow(@RequestHeader String accessToken, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber) {
        return contractService.contractFieldShow(accessToken, contractTemplateNumber);
    }

    /*
     *修改合同字段状态或删除自定义字段
     */
    @PostMapping("changeContractStatus")
    @ResponseBody
    public ResultBean<Object> changeContractStatus(@RequestHeader String accessToken, @RequestBody FieldStatusSetRequestVO fieldStatusSetRequestVO) {
        return contractService.changeContractStatus(accessToken, fieldStatusSetRequestVO);
    }

    /**
     * 新增合同字段
     * @param accessToken 权限鉴定
     * @param contractTemplateNumber 合同编号
     * @param name 名称
     * @return
     */
    @PostMapping("addContractField")
    @ResponseBody
    public ResultBean<Object> addContractField(@RequestHeader String accessToken, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber, @RequestParam(name = "name", required = false) String name) {
        return contractService.addContractField(accessToken, contractTemplateNumber, name);
    }

    /*
     *查看缴费项目
     */
    @PostMapping("showPayProject")
    @ResponseBody
    public ResultBean<Object> showPayProject(@RequestHeader String accessToken, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber) {
        return contractService.showPayProject(accessToken, contractTemplateNumber);
    }

    /*
     *缴费项目保存接口
     */
    @PostMapping("savePayProject")
    @ResponseBody
    public ResultBean<Object> savePayProject(@RequestHeader String accessToken,@RequestBody PayProjectSaveRequestVO payProjectSaveRequestVOS) {
        return contractService.savePayProject(accessToken, payProjectSaveRequestVOS);
    }

    /*
     *合同附件查看
     */
    @PostMapping("contractAttachmentShow")
    @ResponseBody
    public ResultBean<Object> contractAttachmentShow(@RequestHeader String accessToken, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber) {
        return contractService.contractAttachmentShow(accessToken, contractTemplateNumber);
    }

    /*
     *删除自定义附件
     */
    @PostMapping("deleteContractAttachment")
    @ResponseBody
    public ResultBean<Object> deleteContractAttachment(@RequestHeader String accessToken, @RequestParam(name = "contractTemplateNumber", required = false) String contractTemplateNumber, @RequestParam(name = "id", required = false) Long id) {
        return contractService.deleteContractAttachment(accessToken, contractTemplateNumber, id);
    }
    /*
     *合同附件保存接口
     */
    @PostMapping("saveContractAttachment")
    @ResponseBody
    public ResultBean<Object> saveContractAttachment(@RequestHeader String accessToken,@RequestBody List<ContractAttachmentSaveRequestVO> contractAttachmentSaveRequestVOS) {
        return contractService.saveContractAttachment(accessToken, contractAttachmentSaveRequestVOS);
    }

    /**
     * 新增附件
     * @param accessToken 权限鉴定
     * @param contractTemplateCustomAttachmentVO 合同模板附件实体类
     * @return
     */
    @PostMapping("addContractAttachment")
    @ResponseBody
    public ResultBean<Object> addContractAttachment(@RequestHeader String accessToken, ContractTemplateCustomAttachmentVO contractTemplateCustomAttachmentVO) {
        return contractService.addContractAttachment(accessToken, contractTemplateCustomAttachmentVO);
    }
    /**
     * word模板下载,实现了合同模板的下载
     * @param accessToken 权限鉴定
     */
    @GetMapping(value = "contractDownload")
    public void wordDownLoad(@RequestHeader String accessToken) {
        this.contractService.wordDownLoad(accessToken);
    }
    /*
     *导入合同模板
     */
    @PostMapping(value = "/contractImport")
    @ResponseBody
    public ResultBean<Object> wordImport(@RequestHeader String accessToken,
                                  @RequestParam("file") MultipartFile file) {
        return contractService.wordImport(accessToken, file);
    }

}
